package com.example.springboot.controller;

import com.example.springboot.dto.CommentDTO;
import com.example.springboot.entity.ForumComment;
import com.example.springboot.service.ForumCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/comments")
public class ForumCommentController {

    @Autowired
    private ForumCommentService forumCommentService;

    @PostMapping
    public void createComment(@RequestBody ForumComment comment) {
        forumCommentService.createComment(comment);
    }

    @GetMapping("/{commentId}")
    public CommentDTO getComment(@PathVariable Integer commentId) {
        return forumCommentService.getCommentById(commentId);
    }

    @GetMapping("/post/{postId}")
    public List<ForumComment> getCommentsByPost(@PathVariable Integer postId) {
        return forumCommentService.getCommentsByPostId(postId);
    }

    @PutMapping
    public void updateComment(@RequestBody ForumComment comment) {
        forumCommentService.updateComment(comment);
    }

    @DeleteMapping("/{commentId}")
    public void deleteComment(@PathVariable Integer commentId) {
        forumCommentService.deleteComment(commentId);
    }

    @GetMapping("/user/{userId}")
    public List<ForumComment> getCommentsByUser(@PathVariable Integer userId) {
        return forumCommentService.getCommentsByUserId(userId);
    }
}
